//==============================================================================
//
// Title:       PaPsuEloadTest.c
// Purpose:     A short description of the implementation.
//
// Created on:  2013-3-1 at 15:00:35 by Vinson.Zhang
// Copyright:   dafda. All Rights Reserved.
//
//==============================================================================
#include "RFBB.h"         
#include <utility.h>
#include <formatio.h>
#include "agtn330x.h"
#include <formatio.h>
#include <utility.h>
#include "ElectronicLoad.h"


_SHMON_PA_PSU_ELOAD_CMD g_szShmonPaPsuEloadCmd[4] = {{"psu -vset PA1 %d" ,"psu -on PA1","psu -off PA1"},
													 {"psu -vset PA2 %d" ,"psu -on PA2","psu -off PA2"},
													 {"psu -vset PA3 %d" ,"psu -on PA3","psu -off PA3"},
													 {"psu -vset PA4 %d" ,"psu -on PA4","psu -off PA4"}};

_FRMON_TEST_STRUCT_CMD g_cFRMONPaPsuEloadCmd[5] = {{"FRMon,action,load,agent,PsuAccess,Generic,_PsuAccess","done"},
                                                        {"FRMon/Generic/_PsuAccess,action,init,PsuAccess,","done"},
                                                        {"FRMon/Generic/_PsuAccess,action,setVoltage,%d,%d","0x00"},
                                                        {"FRMon/Generic/_PsuAccess,action,setVoltage,%d,0000","0x00"},
                                                        {"FRMon/Generic/_PsuAccess,action,terminate,PsuAccess","done"}};

//_SHMON_PA_PSU_ELOAD_CMD g_szShmonLnaPsuEloadCmd = {"psu -vset LNA %d" ,"psu -on LNA","psu -off LNA"};

/**************************************************************************************************
  Function:        PaPsuEloadEnableTest
  Description:     This test is the tests the PA Psu.
  Calls:           none
  Called By:       dll
  Table Accessed:  none
  Table Updated:   none
  Input:           none
  Output:          error code
  Return:          none
  Test Case ID:    FRHD_PaPsuEloadEnableTest
  Used Command:    g_cFRMONPaPsuEloadCmd
**************************************************************************************************/
void __decldllexp TX_TEST PaPsuEloadEnableTest(tTestData *testData, tTestError *testError)
{

    ErrMsg errMsg = {'\0'};
    ViStatus viStatus; // For esgErrChk -macro
    ERRORINFO errorInfo;   
    ErrMsg szLogMsg;
    CAObjHandle hStepName = 0;
    TSObj_Property stepNumericArrayHandle = 0;
    char* pszStepName = NULL;
    char kszShmonAgent[BUFFER_SIZE_256] ={'\0'};   
    char szElementPath[BUFFER_SIZE_256] ={'\0'};
    

    int  error = 0;
    int  iPassFail = 0;
    int iReturn = 0;
    int iPaPsuNum = 0;
    int iChannel1 = 0;
    int iChannel2 = 0;
    int iSetVoltage = 0;
	int iArryNum = 0;
    float dCurrent = 0.0;

    double dResultVoltage1 = 0.0;
    double dResultVoltage2 = 0.0;

    
    float dDelay = 0.0;
    //////////////////////////////////////////////////////////////////////////   
    // Resolve StepName 
    tsErrChk(TS_SeqContextGetProperty (testData->seqContextCVI, &errorInfo, 
                                       TS_SeqContextStep, CAVT_OBJHANDLE, 
                                       &hStepName));
    tsErrChk(TS_StepGetProperty (hStepName, &errorInfo, TS_StepName, CAVT_CSTRING, 
                                 &pszStepName));

    sprintf( szLogMsg, TEST_NAME_EVENT_FMTSTR, pszStepName );
    ErrChk( EELog_INEventLogLogEvent( g_hEventLog, NULL, szLogMsg ) );

    // Post message to GUI
    tsErrChk(TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                       TS_UIMsg_ProgressText, 0.0,
                                       pszStepName, 0, VTRUE)); 
    
    TS_PropertyGetPropertyObject(testData->seqContextCVI, &errorInfo,"Step.NumericArray", 0, 
                                        &stepNumericArrayHandle );

    //--------------------------------------------------------------------
    // Get Test Parameters from Sequence FileGlobals   
    sprintf(szElementPath, "%s.%s.PARAMETERS.iChannel1", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iChannel1) ); 
    
    sprintf(szElementPath, "%s.%s.PARAMETERS.iChannel2", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iChannel2) ); 

    sprintf(szElementPath, "%s.%s.PARAMETERS.iSetVoltage", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iSetVoltage) );
    
    sprintf(szElementPath, "%s.%s.PARAMETERS.dCurrent", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dCurrent) );


    sprintf(szElementPath, "%s.%s.PARAMETERS.dDelay", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dDelay) );

    if((iChannel1 == 1) || (iChannel2 == 2))
    	{
        iPaPsuNum = 1;
    	}
    else if((iChannel1 == 3) || (iChannel2 == 4))
    	{
        iPaPsuNum = 3; 
    	}
    else
    {
        ;
    }


	// If it's first channel's first case, Run Load and Initial FRMon
	if((iPaPsuNum == 1) && (iSetVoltage == 2400))
    	{
		// InetTelnetOpen(FRCommand)
		g_hFrmonAgent = RfbbInetTelnetOpen (g_szDUTIP, g_iPort, 0);          

    	for(iArryNum = 0;iArryNum < 2;iArryNum++)
    		{
        	sprintf(kszShmonAgent,g_cFRMONPaPsuEloadCmd[iArryNum].cWriteFrmonCmd);    
      		FRmonAgent_String(kszShmonAgent, -1,g_cFRMONPaPsuEloadCmd[iArryNum].cReturnValue, &iPassFail);
	
        	if (iPassFail!=1) 
        		{
				//action terminate
    			sprintf(kszShmonAgent,g_cFRMONPaPsuEloadCmd[4].cWriteFrmonCmd);
    			Frmon_RunCmdNoAck(kszShmonAgent, 1); 
				
    			//InetTelnetClose(FRCommand) 
				InetTelnetClose(g_hFrmonAgent);
            	goto Error;
        		}
			}
		}
	
	//Set Voltage
	sprintf(kszShmonAgent,g_cFRMONPaPsuEloadCmd[2].cWriteFrmonCmd,iPaPsuNum,iSetVoltage);    
    FRmonAgent_String(kszShmonAgent, -1,g_cFRMONPaPsuEloadCmd[iArryNum].cReturnValue, &iPassFail);
	
    //Delay(2.5); // some delay   
    
    //Setup AGN3300A
    ErrChk(SetupLoadCCMode(g_vi_sInitHandleAGN3300A ,iChannel1,dCurrent));
    ErrChk(SetupLoadCCMode(g_vi_sInitHandleAGN3300A ,iChannel2,dCurrent)); 
	
	//Eload on, if Current>0
    if(dCurrent != 0)
	{
	//Enable input channel
    ErrChk(SetInputState(g_vi_sInitHandleAGN3300A,iChannel1,VI_TRUE));
    ErrChk(SetInputState(g_vi_sInitHandleAGN3300A,iChannel2,VI_TRUE));
	}
	
    Delay(2.5); // some delay and Measure the Voltage
    ErrChk(ReadVoltageFromTwoChannelELoad(g_vi_sInitHandleAGN3300A ,iChannel1,dDelay,&dResultVoltage1));
    ErrChk(ReadVoltageFromTwoChannelELoad(g_vi_sInitHandleAGN3300A ,iChannel2,dDelay,&dResultVoltage2));     

	//Eload off, if Current>0
    if(dCurrent != 0)
	{
	//Disable input channel
    ErrChk(SetInputState(g_vi_sInitHandleAGN3300A,iChannel1,VI_FALSE));
    ErrChk(SetInputState(g_vi_sInitHandleAGN3300A,iChannel2,VI_FALSE));
	}
	
	// Off the PA_PSU after 3200 test
    if(iSetVoltage == 3200)
    {
        	sprintf(kszShmonAgent,g_cFRMONPaPsuEloadCmd[3].cWriteFrmonCmd,iPaPsuNum);    
      		Frmon_RunCmdNoAck(kszShmonAgent, 1);
			
			//If last channel's last case ended, action terminate 
			if(iPaPsuNum == 3)
			{
				sprintf(kszShmonAgent,g_cFRMONPaPsuEloadCmd[4].cWriteFrmonCmd);    
      			Frmon_RunCmdNoAck(kszShmonAgent, 1); 
				
				//InetTelnetClose(FRCommand) 
				InetTelnetClose(g_hFrmonAgent);
            	goto Error;
        	}
			
		
	}
    
    Delay(2); // some delay
	

Error:
    
#if(ON_OFF != SIMU_VERS) 

    TS_PropertySetValNumberByOffset( stepNumericArrayHandle, &errorInfo,0, 0, dResultVoltage1);
    TS_PropertySetValNumberByOffset( stepNumericArrayHandle, &errorInfo,1, 0, dResultVoltage2);


    if(iPassFail == 1)
    {
        testData->result = PASS;
    }
    else 
    {
        testData->result = FAIL;
    }

     
    // FREE RESOURCES
	CA_DISCARD_OBJ( stepNumericArrayHandle );
    CA_DISCARD_OBJ( hStepName );
    CA_FREE( pszStepName );

    // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if(error < 0)
    {
        testError->errorFlag = TRUE;
        testError->errorCode = error;
        testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
    }
#else
    testData->result = PASS;
#endif

   // Clear message from GUI
   TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                 TS_UIMsg_ProgressText, 0.0, " ", 0, VTRUE);

   return;    
}
/**************************************************************************************************
  Function:        PaPsuEloadDisableTest
  Description:     This test is the tests the lock detect status of all synthesizers.
  Calls:           none
  Called By:       dll
  Table Accessed:  none
  Table Updated:   none
  Input:           none
  Output:          error code
  Return:          none
  Test Case ID:    FAHA_DigTRX_BIST_SYNTH
  Used Command:    g_szCmonSynOfLock
**************************************************************************************************/
void __decldllexp TX_TEST PaPsuEloadDisableTest(tTestData *testData, tTestError *testError)
{

    ErrMsg errMsg = {'\0'};
    ViStatus viStatus; // For esgErrChk -macro
    ERRORINFO errorInfo;   
    ErrMsg szLogMsg;
    CAObjHandle hStepName = 0;
    TSObj_Property stepNumericArrayHandle = 0;
    char* pszStepName = NULL;
    char kszShmonAgent[BUFFER_SIZE_256] ={'\0'};   
    char szElementPath[BUFFER_SIZE_256] ={'\0'};
    

    int  error = 0;
    int  iPassFail = 0;
    int iReturn = 0;
    int iPaPsuNum = 0;
    int iChannel1 = 0;
    int iChannel2 = 0;
    int iSetVoltage = 0;
    float dCurrent = 0.0;

    double dResultVoltage1 = 0.0;
    double dResultVoltage2 = 0.0;

    
    float dDelay = 0.0;
    //////////////////////////////////////////////////////////////////////////   
    // Resolve StepName 
    tsErrChk(TS_SeqContextGetProperty (testData->seqContextCVI, &errorInfo, 
                                       TS_SeqContextStep, CAVT_OBJHANDLE, 
                                       &hStepName));
    tsErrChk(TS_StepGetProperty (hStepName, &errorInfo, TS_StepName, CAVT_CSTRING, 
                                 &pszStepName));

    sprintf( szLogMsg, TEST_NAME_EVENT_FMTSTR, pszStepName );
    ErrChk( EELog_INEventLogLogEvent( g_hEventLog, NULL, szLogMsg ) );

    // Post message to GUI
    tsErrChk(TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                       TS_UIMsg_ProgressText, 0.0,
                                       pszStepName, 0, VTRUE)); 
    
    TS_PropertyGetPropertyObject(testData->seqContextCVI, &errorInfo,"Step.NumericArray", 0, 
                                        &stepNumericArrayHandle );

    //--------------------------------------------------------------------
    // Get Test Parameters from Sequence FileGlobals   
    sprintf(szElementPath, "%s.%s.PARAMETERS.iChannel1", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iChannel1) ); 
    
    sprintf(szElementPath, "%s.%s.PARAMETERS.iChannel2", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iChannel2) ); 

    sprintf(szElementPath, "%s.%s.PARAMETERS.iSetVoltage", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iSetVoltage) );
    
    sprintf(szElementPath, "%s.%s.PARAMETERS.dCurrent", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dCurrent) );


    sprintf(szElementPath, "%s.%s.PARAMETERS.dDelay", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dDelay) );

    if((iChannel1 == 1) || (iChannel2 == 2))
    {
        iPaPsuNum = 0;
    }
    else if((iChannel1 == 3) || (iChannel2 == 4))
    {
        iPaPsuNum = 2; 
    }
    else
    {
        ;
    }


    g_hShellCommand = RfbbInetTelnetOpen (g_szDUTIP, g_iShellCommandPort, 0); 

    //run Shell Command    
    sprintf(kszShmonAgent,g_szShmonPaPsuEloadCmd[iPaPsuNum].cSetVoltageCmd,iSetVoltage);
    Shmon_RunCmdNoAck(kszShmonAgent,1);
	
	//PA1&2 setting
	sprintf(kszShmonAgent,g_szShmonPaPsuEloadCmd[iPaPsuNum + 1].cSetVoltageCmd,iSetVoltage);
    Shmon_RunCmdNoAck(kszShmonAgent,1); 

    sprintf(kszShmonAgent,g_szShmonPaPsuEloadCmd[iPaPsuNum].cEnablePaPower);
    Shmon_RunCmdNoAck(kszShmonAgent,1);

   
    Delay(2.5); // some delay   
    
     //Setup AGN3300A
    ErrChk(SetupLoadCCMode(g_vi_sInitHandleAGN3300A ,iChannel1,dCurrent));
    ErrChk(SetupLoadCCMode(g_vi_sInitHandleAGN3300A ,iChannel2,dCurrent));    
    ErrChk(ReadVoltageELoadDisabled(g_vi_sInitHandleAGN3300A ,iChannel1,dDelay,&dResultVoltage1));
    ErrChk(ReadVoltageELoadDisabled(g_vi_sInitHandleAGN3300A ,iChannel2,dDelay,&dResultVoltage2));    

    sprintf(kszShmonAgent,g_szShmonPaPsuEloadCmd[iPaPsuNum].cDisablePaPower);
    Shmon_RunCmdNoAck(kszShmonAgent,1);
    Delay(5); // some delay

Error:
    
#if(ON_OFF != SIMU_VERS) 

    TS_PropertySetValNumberByOffset( stepNumericArrayHandle, &errorInfo,0, 0, dResultVoltage1);
    TS_PropertySetValNumberByOffset( stepNumericArrayHandle, &errorInfo,1, 0, dResultVoltage2);


    if(iPassFail == 1)
    {
        testData->result = PASS;
    }
    else 
    {
        testData->result = FAIL;
    }

    InetTelnetClose(g_hShellCommand); 
    // FREE RESOURCES
	CA_DISCARD_OBJ( stepNumericArrayHandle );
    CA_DISCARD_OBJ( hStepName );
    CA_FREE( pszStepName );

    // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if(error < 0)
    {
        testError->errorFlag = TRUE;
        testError->errorCode = error;
        testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
    }
#else
    testData->result = PASS;
#endif

   // Clear message from GUI
   TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                 TS_UIMsg_ProgressText, 0.0, " ", 0, VTRUE);

   return;    
}

/**************************************************************************************************
  Function:        LnaPsuEloadEnableTest
  Description:     This test is the tests the lock detect status of all synthesizers.
  Calls:           none
  Called By:       dll
  Table Accessed:  none
  Table Updated:   none
  Input:           none
  Output:          error code
  Return:          none
  Test Case ID:    FRHD_LnaPsuEloadEnable
**************************************************************************************************/
void __decldllexp TX_TEST LnaPsuEloadEnableTest(tTestData *testData, tTestError *testError)
{

    ErrMsg errMsg = {'\0'};
    ViStatus viStatus; // For esgErrChk -macro
    ERRORINFO errorInfo;   
    ErrMsg szLogMsg;
    CAObjHandle hStepName = 0;
    char* pszStepName = NULL;
    char kszShmonAgent[BUFFER_SIZE_256] ={'\0'};   
    char szElementPath[BUFFER_SIZE_256] ={'\0'};
    

    int  error = 0;
    int  iPassFail = 0;
    int iReturn = 0;
    int iPaPsuNum = 0;
    int iChannel = 0;
    int iSetVoltage = 0;
    float dCurrent = 0.0;

    double dResultVoltage = 0.0;


    
    float dDelay = 0.0;
    //////////////////////////////////////////////////////////////////////////   
    // Resolve StepName 
    tsErrChk(TS_SeqContextGetProperty (testData->seqContextCVI, &errorInfo, 
                                       TS_SeqContextStep, CAVT_OBJHANDLE, 
                                       &hStepName));
    tsErrChk(TS_StepGetProperty (hStepName, &errorInfo, TS_StepName, CAVT_CSTRING, 
                                 &pszStepName));

    sprintf( szLogMsg, TEST_NAME_EVENT_FMTSTR, pszStepName );
    ErrChk( EELog_INEventLogLogEvent( g_hEventLog, NULL, szLogMsg ) );

    // Post message to GUI
    tsErrChk(TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                       TS_UIMsg_ProgressText, 0.0,
                                       pszStepName, 0, VTRUE));    

    //--------------------------------------------------------------------
    // Get Test Parameters from Sequence FileGlobals   
    sprintf(szElementPath, "%s.%s.PARAMETERS.iChannel", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iChannel) ); 
        
    sprintf(szElementPath, "%s.%s.PARAMETERS.dCurrent", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dCurrent) );


    sprintf(szElementPath, "%s.%s.PARAMETERS.dDelay", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dDelay) );

    if(iChannel != 5)
    {
        iPassFail = 0;
        goto Error;
    }
    
    //Setup AGN3300A
    ErrChk(SetupLoadCCMode(g_vi_sInitHandleAGN3300A ,iChannel,dCurrent));

    Delay(2.5); // some delay and Measure the Voltage
    
    ErrChk(ReadVoltageFromOneChannelELoad(g_vi_sInitHandleAGN3300A ,iChannel,dDelay,&dResultVoltage));

Error:
    
#if(ON_OFF != SIMU_VERS) 

    testData->measurement = dResultVoltage;

    if(iPassFail == 1)
    {
        testData->result = PASS;
    }
    else 
    {
        testData->result = FAIL;
    }

    // FREE RESOURCES
    CA_DISCARD_OBJ( hStepName );
    CA_FREE( pszStepName );

    // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if(error < 0)
    {
        testError->errorFlag = TRUE;
        testError->errorCode = error;
        testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
    }
#else
    testData->result = PASS;
#endif

   // Clear message from GUI
   TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                 TS_UIMsg_ProgressText, 0.0, " ", 0, VTRUE);

   return;    
}
/**************************************************************************************************
  Function:        LnaPsuEloadDisableTest
  Description:     This test is the tests the lock detect status of all synthesizers.
  Calls:           none
  Called By:       dll
  Table Accessed:  none
  Table Updated:   none
  Input:           none
  Output:          error code
  Return:          none
  Test Case ID:    FRHD_LnaPsuEloadDisableTest
  **************************************************************************************************/
void __decldllexp TX_TEST LnaPsuEloadDisableTest(tTestData *testData, tTestError *testError)
{

    ErrMsg errMsg = {'\0'};
    ViStatus viStatus; // For esgErrChk -macro
    ERRORINFO errorInfo;   
    ErrMsg szLogMsg;
    CAObjHandle hStepName = 0;
    char* pszStepName = NULL;
    char kszShmonAgent[BUFFER_SIZE_256] ={'\0'};   
    char szElementPath[BUFFER_SIZE_256] ={'\0'};
    

    int  error = 0;
    int  iPassFail = 0;
    int iReturn = 0;
    int iPaPsuNum = 0;
    int iChannel = 0;
    int iSetVoltage = 0;
    float dCurrent = 0.0;

    double dResultVoltage = 0.0;

    
    float dDelay = 0.0;
    //////////////////////////////////////////////////////////////////////////   
    // Resolve StepName 
    tsErrChk(TS_SeqContextGetProperty (testData->seqContextCVI, &errorInfo, 
                                       TS_SeqContextStep, CAVT_OBJHANDLE, 
                                       &hStepName));
    tsErrChk(TS_StepGetProperty (hStepName, &errorInfo, TS_StepName, CAVT_CSTRING, 
                                 &pszStepName));

    sprintf( szLogMsg, TEST_NAME_EVENT_FMTSTR, pszStepName );
    ErrChk( EELog_INEventLogLogEvent( g_hEventLog, NULL, szLogMsg ) );

    // Post message to GUI
    tsErrChk(TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                       TS_UIMsg_ProgressText, 0.0,
                                       pszStepName, 0, VTRUE)); 
    
    //--------------------------------------------------------------------
    // Get Test Parameters from Sequence FileGlobals   
    sprintf(szElementPath, "%s.%s.PARAMETERS.iChannel", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValInteger( testData->seqContextCVI, &errorInfo, szElementPath, 0, &iChannel) ); 
  
    sprintf(szElementPath, "%s.%s.PARAMETERS.dCurrent", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dCurrent) );


    sprintf(szElementPath, "%s.%s.PARAMETERS.dDelay", TESTPLAN_BASE_PATH, pszStepName );   
    tsErrChk( TS_PropertyGetValFloat( testData->seqContextCVI, &errorInfo, szElementPath, 0, &dDelay) );

    if(iChannel != 5)
    {
        iPassFail = 0;
        goto Error;
    }

     //Setup AGN3300A
    ErrChk(SetupLoadCCMode(g_vi_sInitHandleAGN3300A ,iChannel,dCurrent));
     
    Delay(2.5); // some delay
    
    ErrChk(ReadVoltageELoadDisabled(g_vi_sInitHandleAGN3300A ,iChannel,dDelay,&dResultVoltage));

 

Error:
    
#if(ON_OFF != SIMU_VERS) 

    testData->measurement = dResultVoltage;

    if(iPassFail == 1)
    {
        testData->result = PASS;
    }
    else 
    {
        testData->result = FAIL;
    }

    // FREE RESOURCES
    CA_DISCARD_OBJ( hStepName );
    CA_FREE( pszStepName );

    // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if(error < 0)
    {
        testError->errorFlag = TRUE;
        testError->errorCode = error;
        testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
    }
#else
    testData->result = PASS;
#endif

   // Clear message from GUI
   TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                 TS_UIMsg_ProgressText, 0.0, " ", 0, VTRUE);

   return;    
}

